# -*- coding:utf-8 -*-
#! python3
from facecat import *

#更新悬浮状态
#views:视图集合
def updateViewPopup(views):
	updateViewDefault(views)

#绘制视图
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaintPopup(view, paint, clipRect):
	onPaintDefault(view, paint, clipRect)

#绘制视图边线
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaintBorderPopup(view, paint, clipRect):
	onPaintBorderDefault(view, paint, clipRect)

#视图的鼠标移动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseMovePopup(view, mp, buttons, clicks, delta):
	onMouseMoveDefault(view, mp, buttons, clicks, delta)
		
#视图的鼠标按下方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseDownPopup(view, mp, buttons, clicks, delta):
	onMouseDownDefault(view, mp, buttons, clicks, delta)

#视图的鼠标抬起方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseUpPopup(view, mp, buttons, clicks, delta):
	onMouseUpDefault(view, mp, buttons, clicks, delta)

#视图的鼠标点击方法
#view 视图
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks 点击次数
def onClickPopup(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)

#视图的鼠标滚动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseWheelPopup(view, mp, buttons, clicks, delta):
	onMouseWheelDefault(view, mp, buttons, clicks, delta)

#消息循环
def WndProcPopup(hwnd,msg,wParam,lParam):
	global popupPaint
	if (hwnd in popupPaint) == True:
		return WndProcDefault(popupPaint[hwnd],hwnd,msg,wParam,lParam)

popupPaint = dict()

def popupWindow():
	global popupPaint
	pPaint = FCPaint() #创建绘图对象
	pPaint.onPaint = onPaintPopup 
	pPaint.onPaintBorder = onPaintBorderPopup
	pPaint.onMouseDown = onMouseDownPopup 
	pPaint.onMouseMove = onMouseMovePopup 
	pPaint.onMouseUp = onMouseUpPopup
	pPaint.onMouseWheel = onMouseWheelPopup
	pPaint.onClick = onClickPopup
	pPaint.onUpdateView = updateViewPopup
	#初始化窗体
	createWindow(pPaint, "facecat-py2", WndProcPopup)
	popupPaint[pPaint.hWnd] = pPaint
	current_file_path = os.path.abspath(__file__)
	current_file_dir = os.path.dirname(current_file_path)
	file0 = open(current_file_dir + "\\xml\\divexample.xml", encoding="UTF-8")
	xml = file0.read()
	file0.close()
	renderFaceCat(pPaint, xml)
	tabPage = findViewByName("TabPage2", pPaint.views)
	div = FCDiv()
	div.location = FCPoint(50, 50)
	div.size = FCSize(200, 200)
	div.showHScrollBar = True
	div.showVScrollBar = True
	addViewToParent(div, tabPage)
	for i in range(0, 10):
		button = FCButton()
		button.location = FCPoint(i * 40, i * 40)
		button.size = FCSize(100, 20)
		addViewToParent(button, div)
		button.text = "确定"
	showWindow(pPaint)